import Vue from 'vue'
let baseUrl="https://smmf.sdyilian.top/index.php/api/" //https://smmf.chentu.fun/index.php/api/
// let baseUrl="https://smmf.aqsuo.cn/index.php/api/"
Vue.prototype.ajax = (url, data, get, method) => {
	let contentType = method ? 'application/json' : 'application/x-www-form-urlencoded';
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title:'加载中'
		})
		// uni.setStorageSync('loginInfo',
		// 	{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjbGllbnQucnV6aGl5dWFuIiwiYXVkIjoic2VydmVyLnJ1emhpeXVhbiIsImlhdCI6MTYxNDk5NDM5NCwiZXhwIjoxNjE1NTk5MTk0LCJ1aWQiOm51bGx9.EvErgJvEfyw9QeCCYoK_T5kHwLvcDr84zj9wrCyBWQQ","usersig":null,"user_id":null,"userInfo":null
		// })
		uni.request({
			url: baseUrl+ url,
			method: get ? 'GET' : 'POST',
			data: {
				...data
			},
			header: {
				'content-type': contentType,
				'token': uni.getStorageSync('token') ? uni.getStorageSync('token') : ''
			},
			success: ({
				data
			}) => {
				if (data.code == 401) {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: '您登录已过期，请先去授权登录',
						success: function(res) {
							if (res.confirm) {
								
							}
						}
					});
					return false
				}
				resolve(data);
				uni.hideLoading()
			}
		})
	})
};
